package com.example.demo;

import java.util.Arrays;

/**
 * @author jie
 * @date 2021/6/26 -20:18
 */
public class MaoPaoSort {

  public static void main(String[] args) {
    int r[] = {38, 65, 97, 76, 13, 27, 49};
    printR(r);
    maoPaoSort(r);
    printR(r);

  }

  private static void maoPaoSort(int[] r) {
    int count = 0;
    for (int i = 0; i < r.length; i++) {
      for (int j = i + 1; j < r.length; j++) {
        if (r[i] > r[j]) {
          int tmp = r[i];
          r[i] = r[j];
          r[j] = tmp;
        }
        count++;
      }
    }
    System.out.println(count);
  }

  public static void printR(int[] r) {
    System.out.println(Arrays.toString(r));
  }
}
